from django.utils.deprecation import MiddlewareMixin
from django.http import HttpResponseForbidden

class IPMiddleware(MiddlewareMixin):
    def process_request(self, request):
        #非法用户IP
        ips = ["192.168.13.51", "......"]
        # 获取当前的IP
        ip = request.META.get("REMOTE_ADDR")
        # 判断是否是非法
        if ip in ips:
            return HttpResponseForbidden("禁止非法用户访问")


class SetCookieMiddleware(MiddlewareMixin):
    def process_response(self, request, response):
        response.set_cookie("class","0720")
        return response